package com.basketball.core.domain;

import com.basketball.core.exception.BusinessException;
import com.basketball.core.enmu.ErrorEnum;
import lombok.Data;

/**
 * @author xzx
 * @date 2021/8/9 15:27
 */
@Data
public class ResultBean {
    private Boolean success;

    private Integer code;

    private String msg;

    private Object data;

    public ResultBean() {}

    public ResultBean(Boolean success, Integer code, String msg, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static ResultBean businessException(BusinessException e){
        ResultBean result = new ResultBean();
        result.setSuccess(false);
        result.setCode(e.getErrorCode());
        result.setMsg(e.getErrorMsg());
        result.setData(null);
        return result;
    }

    public static ResultBean runTimeException(ErrorEnum errorEnum){
        ResultBean result = new ResultBean();
        result.setData(null);
        result.setMsg(errorEnum.getErrMsg());
        result.setCode(errorEnum.getErrorCode());
        result.setSuccess(false);
        return result;
    }
}
